#ifndef EMW3080_H
#define EMW3080_H

// Arduino versioning.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define clientIDstr   "example"     //ClientID
#define timestamp     "999"         //Timestamp

//ATcmd Format
#define AT                    "AT\r"
#define AT_OK                 "OK"
#define AT_REBOOT             "AT+REBOOT\r"
#define AT_ECHO_OFF           "AT+UARTE=OFF\r"
#define AT_MSG_ON             "AT+WEVENT=ON\r"

#define AT_WIFI_START         "AT+WJAP=%s,%s\r"
#define AT_WIFI_START_SUCC    "+WEVENT:STATION_UP"

#define AT_MQTT_AUTH          "AT+MQTTAUTH=%s&%s,%s\r"
#define AT_MQTT_CID           "AT+MQTTCID=%s|securemode=3\\,signmethod=hmacsha1\\,timestamp=%s|\r"
#define AT_MQTT_SOCK          "AT+MQTTSOCK=%s.iot-as-mqtt.cn-shanghai.aliyuncs.com,1883\r"

#define AT_MQTT_AUTOSTART_OFF "AT+MQTTAUTOSTART=OFF\r"
#define AT_MQTT_ALIVE         "AT+MQTTKEEPALIVE=500\r"
#define AT_MQTT_START         "AT+MQTTSTART\r"
#define AT_MQTT_START_SUCC    "+MQTTEVENT:CONNECT,SUCCESS"
#define AT_MQTT_PUB_SET       "AT+MQTTPUB=%s,1\r"
#define AT_MQTT_PUB_DATA      "AT+MQTTSEND=%d\r"

/*包含标识符（JSON上传数据格式）*/
#define JSON_DATA_PACK        "%s\r"
#define AT_MQTT_PUB_DATA_SUCC "+MQTTEVENT:PUBLISH,SUCCESS"
#define AT_MQTT_UNSUB         "AT+MQTTUNSUB=2\r"
#define AT_MQTT_SUB           "AT+MQTTSUB=2,/sys/%s/%s/thing/service/property/set,1\r"
#define AT_MQTT_SUB_SUCC      "+MQTTEVENT:2,SUBSCRIBE,SUCCESS"

#define DEFAULT_TIMEOUT       10   //seconds
#define BUF_LEN               256
#define BUF_LEN_DATA          256



bool WiFi_init(const char* _wifi_ssid, const char* _wifi_psw);
bool Ali_connect(const char* _ProductKey, const char* _DeviceName, const char* _password);
bool Upload(const char* _pubTopic, const char* _JSON_DATA_PACK);
bool check_send_cmd(const char* cmd, const char* resp, unsigned int timeout);
void cleanBuffer(char *buf, int len);


#endif